{% extends "admin/base_site.html" %}
{% load i18n admin_urls ralph_tags admin_static admin_modify foundation_form foundation_alert sitetree transitions_tags %}

{% block extrahead %}{{ block.super }}
  <script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>
{% endblock %}

{% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} change-form{% endblock %}
{% block content %}
  <div id="content-main">
    <div class="row header">
      <div class="large-6 small-6 columns">
        <h1 class="ellipsis-hidden">{% block title_head %}{% if original %}{{ original }}{% else %}{% trans 'Add' %} {{ opts.verbose_name|lower }}{% endif %}{% endblock %}</h1>
      </div>
      {% if not in_recovery_mode %}
        <div class="large-2 small-2 columns">
          <div class="header-toolbar">
            {% available_transitions original 'status' %}
            {% block object-tools %}
              {% if change %}
                {% if not is_popup %}
                  <ul class="object-tools button-group radius">
                    {% block object-tools-items %}
                      <li>
                        {% url opts|admin_urlname:'history' original.pk|admin_urlquote as history_url %}
                        <a href="{% add_preserved_filters history_url %}" class="historylink small button small right">
                          {% trans "History" %}
                        </a>
                      </li>
                    {% endblock %}
                  </ul>
                {% endif %}
              {% endif %}
            {% endblock %}
          </div>
        </div>
      {% endif %}
    </div>
    <div class="row flex">
      {% if change_views %}
        <div class="small-1 columns no-horizontal-padding elevate">
            {% block tabs %}
              {% views_tabs change_views '' original %}
            {% endblock %}
        </div>
      {% endif %}
      <div class="small-{% if change_views %}11{% else %}12{% endif %} columns no-left-padding right-col">
        <div class="row content">
          <form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form" novalidate>{% csrf_token %}
          {% block form_top %}{% endblock %}
            <div>
              {% block summary %}
                {% include "admin/includes/summary_table.html" %}
              {% endblock %}

              {% if is_popup %}<input type="hidden" name="{{ is_popup_var }}" value="1" />{% endif %}
              {% if to_field %}<input type="hidden" name="{{ to_field_var }}" value="{{ to_field }}" />{% endif %}
              {% if save_on_top %}{% block submit_buttons_top %}{% submit_row %}{% endblock %}{% endif %}
              {% if errors %}
                {% if errors|length == 1 %}
                  {% alert _("Please correct the error below.") 'alert' %}
                {% else %}
                  {% alert _("Please correct the errors below.") 'alert' %}
                {% endif %}
                {% errors adminform.form %}
              {% endif %}
              <div class="row">
                {% block field_sets %}
                  {% for fieldset in adminform %}
                    <div class="small-12 medium-6 large-6 columns">
                      {% include "admin/includes/fieldset.html" %}
                    </div>
                  {% endfor %}
                {% endblock %}
              </div>
              {% block after_field_sets %}{% endblock %}
              {% block inline_field_sets %}
                {% for inline_admin_formset in inline_admin_formsets %}
                  {% include inline_admin_formset.opts.template %}
                {% endfor %}
              {% endblock %}

              {% block after_related_objects %}{% endblock %}

              {# JavaScript for prepopulated fields #}
              {% prepopulated_fields_js %}
              {% if admin_view.show_transition_history and original and not in_recovery_mode %}
                {% transition_history original %}
              {% endif %}
            </div>

            {% block submit_buttons_bottom %}{% ralph_submit_row %}{% endblock %}
          </form>
        </div>
      </div>

    </div>
  </div>
{% endblock %}
{% block extra_scripts %}
  {{ block.super }}
  <script type="text/javascript">
    (function($) {
      $('form#{{ opts.model_name }}_form :input:visible:enabled:first').focus();
    })(ralph.jQuery);
  </script>
  <script type="text/javascript" src="{% static 'js/admin-table.js' %}"></script>
{% endblock %}

